package com.glut.gultguy.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.glut.gultguy.entity.User;
import com.glut.gultguy.mapper.UserMapper;
import com.glut.gultguy.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glut.gultguy.utils.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-09-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired(required = false)
    private UserMapper mapper;

    @Autowired(required = false)
    private SnowflakeIdWorker idWorker;
    @Override
    public User getUserInfo(String openId) {
        User user  = mapper.selectOne(new QueryWrapper<User>().eq("_openid",openId));
        if (user == null){
            return null;
        }
        return user;
    }

    @Override
    public User addUser(User user) {

        user.setId(idWorker.nextId()+"");

       int t =  mapper.insert(user);
        Map<String,Integer> map = new HashMap<>();
        if (t==1){
            return user;
        }else {
            return null;
        }
    }
}
